home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
157_01
/
ch
< prev
next >
Wrap
Text File
|
1987-10-10
|
2KB
|
55 lines
# This shell program 'ch' could be in /usr/bin
# and it is written to use the directory /usr/scratch.
#
#
# /usr/bin/ch
# ===========
#
us=/usr/scratch
> $us/..temp
for i in $*
do
echo "$i" >> $us/..temp
done
tail +3 $us/..temp >$us/.temp
sed "s/$1/$2/" $us/.temp >$us/..temp
<$us/.temp tr \\12 \\40 >$us/temp.
<$us/..temp tr \\12 \\40 >$us/temp..
echo 'mv ' >$us/.temp
echo >>$us/.temp
echo >>$us/temp.
echo >>$us/temp..
cat $us/temp. $us/temp.. $us/.temp > $us/..temp
tp $us/..temp > $us/.temp
awk '{print $3, $1, $2}' $us/.temp >$us/temp.
sh < $us/temp.
rm $us/.temp $us/..temp $us/temp. $us/temp..
#
# This shell program changes filenames taking advantage of
# existing filename matching capabilities of the shell.
# The shell supplies a list of filenames to be edited after
# the first three arguments on the command line.
#
# The first, arg(0), is the command `ch'.
# The second, arg(1), is the search pattern in the filename - a la `ed'
# The third, arg(2), is the substitute string.
#
# As an example, to prefix all filenames in the current directory
# that ends in `.c' with the underscore; we issue the command:
#
# ch '^' _ *.c
#
# Our current directory with the following files:
#
# proga.c progb.c progc.c progd.c
# xanother yanother zanother
#
# would look like this after the execution of the shell program `ch':
#
# _proga.c _progb.c _progc.c _progd.c
# xanother yanother zanother
#
# Note that the ch file should be placed in /usr/bin with mode 775.
# Also, this program needs a shared scratch directory `/usr/scratch'
# with mode 777. Both should be owned by `root'.
ä.